package com.skywolf.chem.match.controller;


import com.skywolf.chem.common.sysconfig.response.RespData;
import com.skywolf.chem.match.entity.ApplyUserInfo;
import com.skywolf.chem.match.params.param.ApplyUserInfoHistoryParam;
import com.skywolf.chem.match.service.IApplyUserInfoService;
import com.skywolf.chem.match.service.impl.ApplyUserInfoServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 通讯录管理 前端控制器
 * </p>
 *
 * @author sj
 * @since 2021-09-24
 */
@AllArgsConstructor
@RestController
@RequestMapping("/match/apply/info")
@Api(value = "赛事：通讯录管理", tags = {"赛事：通讯录管理API"})
public class ApplyInfoController extends BaseController {

    private final IApplyUserInfoService userInfoService;

    @ApiOperation(value = "修改通讯录用户信息", notes = "修改通讯录用户信息")
    @PostMapping("/update")
    public RespData updateHistoryUser(@RequestBody @Validated ApplyUserInfoHistoryParam param) throws Exception {
        userInfoService.updateHistoryUser(getUserId(), param);
        return RespData.success();
    }


    @ApiOperation(value = "新增通讯录用户信息", notes = "新增通讯录用户信息")
    @PostMapping("/create")
    public RespData createHistoryUser(@RequestBody @Validated ApplyUserInfoHistoryParam param) throws Exception {
        userInfoService.createHistoryUser(getUserId(), param);
        return RespData.success();
    }


    @ApiOperation(value = "根据id删除通讯录用户信息", notes = "根据id删除通讯录用户信息")
    @GetMapping("/deleted/{id}")
    @ApiImplicitParam(name = "id", value = "通讯录id", paramType = "path", dataType = "Long")
    public RespData deletedHistoryUser(@PathVariable("id") Long id) {
        userInfoService.removeById(id);
        return RespData.success();
    }

    @ApiOperation(value = "获取通讯录列表", notes = "获取通讯录列表")
    @GetMapping("/list")
    public RespData<List<ApplyUserInfoHistoryParam>> getList() {
        List<ApplyUserInfoHistoryParam> params = userInfoService.getList(getUserId());
        return RespData.success(params);
    }

    @ApiOperation(value = "根据id获取通讯录用户信息", notes = "根据id获取通讯录用户信息")
    @GetMapping("/get/{id}")
    @ApiImplicitParam(name = "id", value = "通讯录id", paramType = "path", dataType = "Long")
    public RespData<ApplyUserInfoHistoryParam> getInfo(@PathVariable("id") Long id) throws Exception {
        ApplyUserInfoHistoryParam param = userInfoService.getInfo(id);
        return RespData.success(param);
    }


}
